{% extends 'open-course-manage/layout.html.twig' %}
{% block title %}{{'my.teaching.open_course.recommend_setting.title'|trans}} - {{ parent() }}{% endblock %}
{% set side_nav = 'marketing' %}
{% do script(['app/js/open-course-manage/recommend-course/index.js'])%}
{% block page_title %}
  {{'my.teaching.open_course.recommend_setting.title'|trans}}
  <div class="pull-right">
    <button class="cd-btn cd-btn-success cd-btn-sm panel-bar" data-toggle="modal" data-target="#modal" data-url="{{path('open_course_manage_course_pick', {id:course['id']})}}">{{ 'my.teaching.open_course.recommend_setting.add_course_btn'|trans }}</button>
  </div>
{% endblock %}

{% block main_body %}
  <form class="form-horizontal" id="recommend-course-form" method="post" action="{{ path('open_course_manage_marketing',{id:course.id}) }}">
    {% set openCourse = course %}
    {{ web_macro.flash_messages() }}

    <div class="form-group" id="courses-form-group">
      <div class="col-md-12 controls">
        <ul class="js-course-list-group sortable-list course-wide-list courses-selected" id="course-list-group" data-role="list" >

          {% for recommendId, courseSet in courseSets %}
            {% set showUrl = path('course_show',{id: courseSet.defaultCourseId}) %}

            <li class="course-item item-{{courseSet.id}} clearfix" data-role="item" >
              <input type="hidden" name="recommendIds[]" value="{{ recommendId }}" />

              <span class="glyphicon glyphicon-resize-vertical sort-handle" style="padding: 50px 20px 0 20px"></span>
              <a class="course-picture-link" href="{{ showUrl }}" target="_blank">
                {% if courseSet.type == 'live' %}
                  <span class="tags">
                    <span class="tag-live"></span>
                  </span>
                {% endif %}
                <img class="course-picture" src="{{ filepath(course_set_cover(courseSet, 'middle'), 'courseSet.png') }}" alt="{{ courseSet.title }}">
              </a>

              <button class="close js-delete-btn course-close-btn mrl mts mll" data-role="item-delete" type="button" title="form.btn.delete" data-cancel-url="{{ path('open_course_manage_recommend_course_delete', {id:openCourse.id, recommendId: recommendId}) }}" data-recommend-id="{{ recommendId }}" data-id="{{courseSet.id}}">× </button>

              <div class="course-body clearfix">
                <div class="color-gray cd-mr40 mls pull-right">
                  {% include 'open-course-manage/course-set-price-interval.html.twig' %}
                </div>

                <h4 class="course-title text-overflow mv0">
                {% if courseSet.type == 'normal' or courseSet.type == 'live' %}
                  {% if courseSet.serializeMode=='serialized' %}
                    <span class="label label-success ">{{ 'my.teaching.open_course.recommend_setting.serializeMode.live'|trans }}</span>
                  {% elseif courseSet.serializeMode=='finished' %}
                    <span class="label label-warning ">{{ 'my.teaching.open_course.recommend_setting.serializeMode.finished'|trans }}</span>
                  {% endif %}
                {% endif %}
                <a href="{{ showUrl }}" target="_blank" title="{{ courseSet.title }}">{{ courseSet.title }}</a>
                </h4>

                <div class="course-about ellipsis text-sm">{{ courseSet.subtitle }}</div>

                <div class="course-footer clearfix">
                  {% set defaultCourse = courses[courseSet.defaultCourseId]|default(null) %}
                  {% set teacher = users[defaultCourse.teacherIds|first|default(null)]|default(null) %}
                  {% if teacher %}
                    <div class="teacher">
                      <a href="{{ path('user_show', {id:teacher.id}) }}" target="_blank"><img src="{{ filepath(teacher.smallAvatar, 'avatar.png') }}" class="teacher-avatar"></a>
                      <a class="teacher-nickname ellipsis" target="_blank"  href="{{ path('user_show', {id:teacher.id}) }}">{{ teacher.nickname }}</a>
                      <span class="teacher-title ellipsis">{{ teacher.title }}</span>
                    </div>
                  {% endif %}

                  <div class="course-metas">

                    {% if setting('course.show_student_num_enabled', '1') == 1  %}
                      <span class="color-gray text-sm">{{ courseSet.studentNum }}{{'site.default.student'|trans}}</span>
                      {#<span class="divider"></span>#}
                    {% endif %}

                    {#<span class="color-gray text-sm">
                        {{course.lessonNum}}个任务
                    </span>#}
                    {#{% if course.type == 'normal' or course.type == 'live' %}
                      <span class="divider"></span>

                      <span class="color-gray text-sm">
                        有效期:
                        {% if course.expiryDay %}
                          {{course.expiryDay}}天
                        {% else %}
                          永久
                        {% endif %}
                      </span>
                    {% endif %}#}
                  </div>

                </div>

              </div>
            </li>

          {% endfor %}

        </ul>
      </div>
    </div>

    {% if courseSets %}
      <div class="form-group">
        <div class="col-md-offset-9 col-md-3 controls">
          <button type="submit" class="cd-btn cd-btn-primary pull-right">{{ 'my.teaching.open_course.recommend_setting.save_btn'|trans }}</button>
        </div>
      </div>
    {% else %}
      <div class="empty">{{ 'my.teaching.open_course.recommend_setting.course_empty'|trans }}</div>
    {% endif %}

    <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">

  </form>
{% endblock %}
